package com.macro.mall.tiny.modules.foster.controller;

import com.macro.mall.tiny.common.api.CommonResult;
import com.macro.mall.tiny.config.AlipayConfig;
import com.macro.mall.tiny.modules.foster.model.dto.AliPayParam;
import com.macro.mall.tiny.modules.foster.service.AlipayService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import io.swagger.v3.oas.annotations.tags.Tag;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.io.IOException;

/**
 * @auther macrozheng
 * @description 支付宝支付Controller
 * @date 2023/9/8
 * @github https://github.com/macrozheng
 */
@RestController
@Api(tags = "AlipayController")
@Tag(name = "AlipayController", description = "支付宝支付相关接口，已弃用")
@RequestMapping("/foster/alipay")
@CrossOrigin
public class AlipayController {

    @Autowired
    private AlipayConfig alipayConfig;
    @Autowired
    private AlipayService alipayService;

    @ApiOperation("支付宝电脑网站支付")
    @RequestMapping(value = "/pay", method = RequestMethod.POST)
    public String pay(@RequestBody AliPayParam aliPayParam) throws IOException {
        String pay = alipayService.pay(aliPayParam);
        return pay;
    }

    @ApiOperation(value = "支付宝统一收单线下交易查询",notes = "订单支付成功返回：TRADE_SUCCESS，可以只传outTradeNo，就是订单id")
    @RequestMapping(value = "/query", method = RequestMethod.GET)
    @ResponseBody
    public CommonResult<String> query(String outTradeNo, String tradeNo){
        return CommonResult.success(alipayService.query(outTradeNo,tradeNo));
    }
}